import { reactive } from 'vue';

export default function importConfig(props, emits) {
  const { emit } = emits;
  const base = reactive<any>({
    showColumns: null,
    showSize: 'medium',
  });

  /**
   * @exports init 初始化
   */
  const init = () => {
    base.showColumns = base.cloneColumns = props.columns;
  };

  /**
   * @exports densityList table 大小类
   */
  const densityList = [
    {
      name: '迷你',
      value: 'mini',
    },
    {
      name: '偏小',
      value: 'small',
    },
    {
      name: '标准',
      value: 'medium',
    },
    {
      name: '偏大',
      value: 'large',
    },
  ];

  /**
   * @exports handleSelectDensity tabel数据大小显示控制器
   */
  const handleSelectDensity = (val: string) => {
    base.showSize = val;
    emit('update:size', base.showSize);
  };

  /**
   * @exports handleChange tabel数据列显示控制器
   */
  const handleChange = () => {
    base.cloneColumns = base.showColumns.filter((item: any) => {
      return item.checked === true;
    });
    emit('update:columns', base.cloneColumns);
  };

  /**
   * @exports refresh 刷新表单数据功能
   */
  const refresh = () => {
    emit('refresh');
  };

  const changeSearchBar = () => {
    emit('changeSearchBar');
  };

  /**
   * @exports tapNew 点击新建时的操作
   */
  const tapNew = () => {
    emit('tapNew');
  };

  const tapUpdate = () => {
    emit('tapUpdate');
  };

  const tapDel = () => {
    emit('tapDel');
  };

  const tapFold = () => {
    emit('tapFold');
  };

  return {
    densityList,
    base,
    handleSelectDensity,
    init,
    handleChange,
    refresh,
    changeSearchBar,
    tapNew,
    tapUpdate,
    tapDel,
    tapFold,
  };
}
